from selenium import webdriver

# find/click等浏览器操作


class BaseDriver:
    def __init__(self, driver=None):
        # 处理driver
        if driver is None:
            opt = webdriver.ChromeOptions()
            opt.debugger_address = "localhost:9222"
            self._driver = webdriver.Chrome(options=opt)
            self._driver.implicitly_wait(10)
            self._driver.get("https://ceshiren.com")
        else:
            self._driver = driver

    def find(self, by, value):
        result = self._driver.find_element(by, value)
        return result

    def find_content(self, by, value, content: str):
        result = self._driver.find_element(by, value).send_keys(content)
        return result

    def finds(self, by, value):
        result = self._driver.find_elements(by, value)
        return result

    def find_and_click(self, by, value):
        result = self._driver.find_element(by, value).click()
        return result
